<template>
	<view class="worthtreasure">
		<view class="head" :style="{ backgroundImage: 'url(' + $util.img('upload/uniapp/contribution/worthtreasure_headbgm.png') + ')' }">
			<!-- <view class="active-rule" @click="active_ruleClick">活动规则</view> -->
			<view class="lottery_record" @click="lottery_recordClick">夺宝记录</view>
			<view class="contribution_value" :style="{ backgroundImage: 'url(' + $util.img('upload/uniapp/contribution/contribution_value@2x.png') + ')' }">
				<view class="contribution">我的数字资产</view>
				<view class="value">{{contribution_value}}</view>
			</view>
		</view>
		<view class="list">
			<view class="list_item" v-for="(item,index) in listArr" :key="index">
				<view class="view1">
					<view class="label">第{{item.stage}}期</view>
					<image class="goodsimg" :src="item.goods_img"></image>
				</view>
				<view class="item_content">
					<view class="item_name">{{item.goods_name}}</view>
					<view class="item_num">{{item.exchange_value}}</view>
					<view class="v1 flex-between">
						<view class="v1_left">
							<progress class="pro" :percent="item.have_value/item.exchange_value*100" border-radius=10 stroke-width="8" activeColor="#FF4544" backgroundColor="#FFCE89"></progress>
							<view class="v2">还差{{item.exchange_value - item.have_value}}数字资产</view>
						</view>
						<view class="indiana_but" @click.stop="tureDetail(item.id)">立即夺宝</view>
					</view>
				</view>
			</view>
			<ns-empty v-if="!listArr.length" text="暂无活动记录" :isIndex="!1" :fixed="!1"></ns-empty>
		</view>
		<loading-cover ref="loadingCover"></loading-cover>
	</view>
</template>

<script>
	export default{
		data() {
			return {
				mask:false,
				contribution_value:0,//我的数字资产
				listArr:[],
				page:1,
				page_size:15,
				page_count:''
			}
		},
		onLoad() {
			uni.setNavigationBarTitle({
				title: '数字资产夺宝'
			})
		},
		onShow() {
			if (uni.getStorageSync('token')) {
				this.page = 1;
				this.getData()
				this.getListData()
			} else {
				this.$util.redirectTo(
					'/otherpages/login/login/login', {
						back: '/promotionpages/contribution/worthtreasure'
					},
					'redirectTo'
				);
			}
		},
		onReachBottom(){
			this.getMoreData()
		},
		methods:{
			getData() {
				this.$api.sendRequest({
					url: '/loot/api/Activity/myContributionValue',
					success: res => {
						if (res.code == 0) {
							this.contribution_value = res.data.point
						}
						if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
					},
					fail: res => {
						if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
					}
				})
			},
			active_ruleClick(){
				console.log('跳转活动规则')
			},
			lottery_recordClick(){//跳转开奖记录
				this.$util.redirectTo('/promotionpages/contribution/iottery_record');
			},
			tureDetail(id){
				this.$util.redirectTo('/promotionpages/contribution/details?id=' + id);
			},
			makesure(val){
				val == 1 ? this.mask = false : this.mask = true;
			},
			getListData(){
				this.$api.sendRequest({
					url:'/loot/api/Activity/getActivityGoodsList',
					data:{
						page:this.page,
						page_size:this.page_size
					},
					success:res =>{
						if(res.code==0){
							let newArr = []
							newArr = res.data.list
							if(this.page==1){
								this.listArr = []
							}
							this.listArr = this.listArr.concat(newArr)
							this.page_count = res.data.page_count
						}else{
							this.$util.showToast({
								title: res.message
							});
						}
					}
				});
			},
			getMoreData(){
				if(this.page < this.page_count){
					this.page++;
					this.getListData();
				}
			}
		},
	}
</script>

<style lang="scss">
	@mixin bgm($imagename) {
		background-size: 100% 100%;
		background-repeat: no-repeat;
		// background-image: url('../../common/img/contribution/'+$imagename);
	}
	@mixin flex($jusitify,$align) {
		display: flex;
		justify-content: $jusitify;
		align-items: $align;
	}
	.flex-left{
		display: flex;
		justify-content: flex-start;
		align-items: center;
	}
	.flex-between{
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	.worthtreasure{
		width: 750rpx;
		min-height: 100vh;
		padding-bottom: 60rpx;
		background: #FFF3E6;
		.head{
			width: 100%;
			height: 660rpx;
			@include bgm('worthtreasure_headbgm.png')
			.active-rule{
				position: absolute;
				right: 0;
				top: 48rpx;
				padding: 7rpx 0 3rpx 10rpx;
				text-align: center;
				width: 68rpx;
				height: 54rpx;
				background: linear-gradient(180deg, #FFF7D5 0%, #FFD6B0 100%);
				box-shadow: 0 6rpx 8rpx 0 #DB1010;
				border-radius: 100rpx 0 0 100rpx;
				font-size: 24rpx;
				font-family: SourceHanSansCN-Regular, SourceHanSansCN;
				font-weight: 400;
				color: #C64D06;
				line-height: 26rpx;
			}
			.lottery_record{
				position: absolute;
				right: 0;
				top: 150rpx;
				padding: 7rpx 0 3rpx 10rpx;
				text-align: center;
				width: 68rpx;
				height: 54rpx;
				background: linear-gradient(180deg, #FFF7D5 0%, #FFD6B0 100%);
				box-shadow: 0 6rpx 8rpx 0 #DB1010;
				border-radius: 100rpx 0 0 100rpx;
				font-size: 24rpx;
				font-family: SourceHanSansCN-Regular, SourceHanSansCN;
				font-weight: 400;
				color: #C64D06;
				line-height: 26rpx;
			}
			.contribution_value{
				position: absolute;
				left: 0;
				top: 460rpx;
				width: 282rpx;
				height: 92rpx;
				margin-left: 234rpx;
				@include bgm('contribution_value@2x.png');
				text-align: center;
				.contribution{
					margin-top: 12rpx;
					height:34rpx;
					line-height: 34rpx;
					font-size: 24rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #C64D06;
				}
				.value{
					margin-top: 2rpx;
					height: 40rpx;
					line-height: 40rpx;
					font-size: 40rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #C64D06;
				}
			}
		}
		.list{
			padding: 22rpx 20rpx 0 20rpx;
			.list_item{
				background: #FFFFFF;
				border-radius: 16px;
				margin-bottom: 20rpx;
				display: flex;
				.view1{
					margin: 20rpx;
					min-width: 272rpx;
					max-width: 272rpx;
					height: 272rpx;
					.goodsimg{
						width: 100%;
						height: 100%;
						background: #31BB6D;
					}
					.label{
						position: absolute;
						z-index: 1;
						width: 104rpx;
						height: 40rpx;
						background: linear-gradient(180deg, #FFEACB 0%, #FFCE89 100%);
						border-radius: 16rpx 0rpx 16rpx 0rpx;
						line-height: 33rpx;
						font-size: 24rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #C64D06;
						display: flex;
						justify-content: center;
						align-items: center;
					}
				}
				.item_content{
					padding: 20rpx 20rpx 20rpx 0;
					
					.item_name{
						height: 92rpx;
						line-height: 46rpx;
						font-size: 32rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #303133;
						overflow: hidden;
						word-break: break-all;  /* break-all(允许在单词内换行。) */
						text-overflow: ellipsis;  /* 超出部分省略号 */
						display: -webkit-box; /** 对象作为伸缩盒子模型显示 **/
						-webkit-box-orient: vertical; /** 设置或检索伸缩盒对象的子元素的排列方式 **/
						-webkit-line-clamp: 2; /** 显示的行数 **/
					}
					.item_num{
						margin-top: 60rpx;
						line-height: 28rpx;
						height: 28rpx;
						font-size: 36rpx;
						font-family: PingFangSC-Medium, PingFang SC;
						font-weight: 500;
						color: #FF4544;
					}
					.v1{
						margin-top: 28rpx;
						.v1_left{
							width: 200rpx;
							.v2{
								margin-top: 8rpx;
								height: 28rpx;
								line-height: 28rpx;
								font-size: 20rpx;
								font-family: PingFangSC-Regular, PingFang SC;
								font-weight: 400;
								color: #909399;
							}
						}
						.indiana_but{
							margin-left: 34rpx;
							width: 144rpx;
							height: 64rpx;
							background: #FF4544;
							border-radius: 44rpx;
							line-height: 33rpx;
							font-size: 24rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							color: #FFFFFF;
							display: flex;
							align-items: center;
							justify-content: center;
						}
					}
				}
			}
		}
	}
</style>
